The grammar Environment

The grammar environment will take a context free grammar, written using the notation used in LP811 and pretty print the grammar. The grammar environment has up to five optional parameters, which specify the notation to be used to print the grammar. Note that whichever notation is chosen for the output, the grammar environment only recognises the LP81 notation in the input.

A short summary of the notation used in LP81 is presented here for those readers not familiar with it. It is assumed that the reader is familiar with context free grammars.

The optional parameters of the grammar environment are all of the form [(SYMBOL NAME)REPLACEMENT], where SYMBOL NAME is one of ``colon'', ``semicolon'', ``period'', ``comma'' and ``quote''. REPLACEMENT is then the text2 that will replace the symbol specified by SYMBOL NAME. Note that a new line (\\) can be included in the replacement text, in which case the output will automatically start on a new line after each occurrence of the symbol specified. The default values are

Strings in the grammar environment are indicated by double-quote symbols ("). The colon, semicolon, period and comma have no special significance within a string, but are the same simple characters they are outside the grammar environment. A double-quote symbol can be produced by using the \quotesymbol command.

All of these features are demonstrated below. The text:

\begin{grammar}
  [(colon){::$\Rightarrow$}]
  [(semicolon){ $|$}]
  [(period){ \rule{1ex}{1ex}\\}]
  [(quote){`}{'}]
grammar environment:\\
  "\verb!begin{grammar}!",\\
	optional parameters,\\
	 context free grammar,\\
	  "\verb!end{grammar}!".
optional parameters:\\
  "[",optional parameter,"]",\\
   optional parameters;.
optional parameter:\\
  "(", specification, ")",\\
   \LaTeX\ strings.
\LaTeX\ strings:\\
   \LaTeX\ string;\\
   "\{",\LaTeX\ string,"\}",\\
   \LaTeX\ strings.
specification:\\
  "{\tt colon}";\\
  "{\tt semicolon}";\\
  "{\tt period}";\\
  "{\tt comma}";\\
  "{\tt quote}".
context free grammar:\\
  rule,\\
  context free grammar;.
rule:\\
  nonterminal,":",\\
  alternatives,".".
alternatives:\\
  alternative,";",\\
   alternatives;.
alternative:
  members;.
members:\\
  member,",",members;\\
  member.
member:\LaTeX\ string,string.
string:"{\tt \quotesymbol}",
  \LaTeX\ string ,
  "{\tt \quotesymbol}".
\end{grammar}
produces the following output:
\begin{grammar}[(colon){::$\Rightarrow$}]
[(semicolon){ $\vert$}]
[(period){ \...
...g:''{\tt\quotesymbol}'',
\LaTeX\ string ,
''{\tt\quotesymbol}''.
\end{grammar}